package shopcomputer;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/showcomputer")
public class ShowComputerServlet extends HttpServlet {
	
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		
		Object obj = request.getSession().getAttribute("myComputer");
		Set<Computer> myComputer = (Set<Computer>)obj;
		
		PrintWriter out = response.getWriter();
		
		out.print("<html><body><table border='1'>");
		for(Computer computer:myComputer) {
			out.print("<tr>");
			out.print("<td>"+ computer.getBrand() +"</td>");
			out.print("<td>"+ computer.getColor() +"</td>");
			out.print("<td>"+ computer.getPrice() +"</td>");
			out.print("</tr>");
			
		}
		
		out.print("</table></body></html>");
		out.flush();
		out.close();
		
		
	}
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
	
	

}








